package com.mk.settlement.service.test;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Order {
    
    private BigDecimal price;
    
    private Date date;
    
    private String sDate;
    
    private int payType;

    public int getPayType() {
        return payType;
    }

    public void setPayType(int payType) {
        this.payType = payType;
    }

    public Date getDate() {
        return date;
    }
    
    public String getSDate() {
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        
        return sdf.format(getDate());
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }
    
    public static Date getMonday(String date)throws Exception{
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(date));
        int week = cal.get(Calendar.DAY_OF_WEEK);
        if(week>2){
            cal.add(Calendar.DAY_OF_MONTH,-(week-2)+7);
        }else{
            cal.add(Calendar.DAY_OF_MONTH,2-week+7);
        }
        return cal.getTime();
    }
    
    public static Date nextMonthFirstDate(String date) throws Exception{
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdf.parse(date));
        
//        Calendar calendar = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.add(Calendar.MONTH, 1);
        return cal.getTime();
    }
}
